package com.huanf.controller;

import com.huanf.response.ResponseResult;
import com.plexpt.chatgpt.entity.chat.ChatCompletion;
import com.plexpt.chatgpt.entity.chat.ChatCompletionResponse;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/gpt")
public class GptController extends BaseController {

    //--------------------------------------------全文响应--------------------------------------------

    @GetMapping("/v3")
    //http://127.0.0.1:90/gpt/v3?q=xxxxx
    public ResponseResult gpt3(@RequestParam("q")String q, HttpServletRequest request){
        ChatCompletionResponse response = initChatAnyTemplate(request, getApi(), q, initChatGPT(getApi()), ChatCompletion.Model.GPT_3_5_TURBO);
        return getResponseResult(q, request, response);
    }

    @GetMapping("/v4")
    //http://127.0.0.1:90/gpt/v4?q=xxxxx
    public ResponseResult gpt4(@RequestParam("q")String q, HttpServletRequest request){
        ChatCompletionResponse response = initChatAnyTemplate(request, getApi(), q, initChatGPT(getApi()), ChatCompletion.Model.GPT4o);
        return getResponseResult(q, request, response);
    }


    //--------------------------------------------流式响应--------------------------------------------

    @GetMapping("/v3-flow")
    // http://127.0.0.1:90/gpt/v3-flow?q=你好
    public SseEmitter gpt3FlowTest(@RequestParam("q") String q, HttpServletRequest request, HttpServletResponse response) {
        return getEmitter(q, request, response, ChatCompletion.Model.GPT_3_5_TURBO);
    }

    @GetMapping("/v4-flow")
    // http://127.0.0.1:90/gpt/v4-flow?q=你好
    public SseEmitter gpt4FlowTest(@RequestParam("q") String q, HttpServletRequest request, HttpServletResponse response) {
        return getEmitter(q, request, response, ChatCompletion.Model.GPT4o);
    }

    /**
     * 测试邮件 解开即可测试
     * @return
     */
    //@GetMapping("/mail")
    //public ResponseResult mail(){
    //    return sendMailCode().equals(true) ? ResponseResult.mailSuccess() : ResponseResult.mailFail();
    //}
}